package gods.bubble.common;

public class StandardDocument implements Comparable<StandardDocument>{
	public String fileName;

	public String url;
	public String title;
	public String content;
	public String sublinks;
	
	public String raw_html;

	public double score;
	public double lucene_score;
	public double pagerank;
	
	private double[] coefficients = {1, 80000, 3000};

	public StandardDocument() {
		url = null;
		title = null;
		content = null;

		lucene_score = 0;
		pagerank = 0;
	}
	
	public void makeScore() {
		score = coefficients[0] * lucene_score + coefficients[1] * pagerank + coefficients[2] / Math.pow(url.length(), 2);
		
		//Weight increase for main page
		if (url.contains("\\publish\\") ) {
			score = score * 1.5;
		}
		
		//Weight increase for index
		if (!(url.endsWith("htm") || url.endsWith("html"))) {
			score = score * 1.2;
		}
	}

	public String toXml() {
		StringBuilder sb = new StringBuilder();

		sb.append("<url>\n" + url + "\n</url>\n");
		sb.append("<title>\n" + title + "\n</title>\n");
		sb.append("<content>\n" + content + "\n</content>\n");

		return sb.toString();
	}
	
	public String toHtml() {
		StringBuilder sb = new StringBuilder();
		
		sb.append("<a href=\"http://" + url + "\"><font size=\"3\" face=\"arial\">" + title + "</font></a>");
		sb.append("<br/>");

		sb.append("<font size=\"2\">" + content + "</font>");
		sb.append("<br/>");
		
		sb.append("<b><font size=\"1\" face=\"arial\" color=\"009966\">" + url + "</font></b>");
		sb.append("<br/>");
		
		sb.append("<font size=\"1\" face=\"arial\" color=\"gray\">score = " + score + ";lucene = " + coefficients[0] * lucene_score + ";pagerank = " + coefficients[1] * pagerank+ ";length = " + coefficients[2] / Math.pow(url.length(), 2) + "</font>");
		sb.append("<br/><br/>");

		String html = sb.toString();
		html = html.replaceAll("\n", "<br/>");
		html = html.replaceAll("[=]{2,}", "");

		return html;
	}

	@Override
	public int compareTo(StandardDocument arg0) {
		return Double.compare(arg0.score, this.score);
	}
}
